const express = require('express');

const app = express();
app.use('/public/', express.static('./public/'));
app.engine('html', require('express-art-template'));

const comments = [
    {
      name: '张三',
      message: '今天天气不错！',
      dateTime: '2015-10-16'
    },
    {
      name: '张三2',
      message: '今天天气不错！',
      dateTime: '2015-10-16'
    },
    {
      name: '张三3',
      message: '今天天气不错！',
      dateTime: '2015-10-16'
    },
    {
      name: '张三4',
      message: '今天天气不错！',
      dateTime: '2015-10-16'
    },
    {
      name: '张三5',
      message: '今天天气不错！',
      dateTime: '2015-10-16'
    }
]
app.get('/', function (req, res) {
    res.render('index.html', {
        comments: comments
    });
});

app.get('/post', function(req, res) {
    res.render('post.html');
});

app.get('/pinglun', function(req, res) {
    const comment = req.query;
    comment.dateTime = '2021-07-28 00:00:00';
    comments.unshift(comment);
    res.redirect('/');
});



app.listen(3000, function() {
    console.log('port 3000');
})